#include "internal.h"

static void place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
{
    // TODO
}

static void requeue_delayed_entity(struct sched_entity *se)
{
}

static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
{
    rb_add_augmented_cached(&se->run_node, &cfs_rq->tasks_timeline,
                            __entity_less, &min_vruntime_cb);
}

static void enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
{
    bool curr = cfs_rq->curr == se;

    /*
     * If we're the current task, we must renormalise before calling
     * update_curr().
     */
    if (curr)
        place_entity(cfs_rq, se, flags);

    account_entity_enqueue(cfs_rq, se);

    if (!curr)
        __enqueue_entity(cfs_rq, se);

    se->on_rq = 1;
}

static void enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
{
    struct cfs_rq *cfs_rq;
    struct sched_entity *se = &p->se;
    int h_nr_idle = task_has_idle_policy(p);
    int h_nr_runnable = 1;
    int task_new = !(flags & ENQUEUE_WAKEUP);
    int rq_h_nr_queued = rq->cfs.h_nr_queued;
    u64 slice = 0;

    /*
     * The code below (indirectly) updates schedutil which looks at
     * the cfs_rq utilization to select a frequency.
     * Let's add the task's estimated utilization to the cfs_rq's
     * estimated utilization, before we update schedutil.
     */
    if (!(p->se.sched_delayed && (task_on_rq_migrating(p) || (flags & ENQUEUE_RESTORE))))
        util_est_enqueue(&rq->cfs, p);

    if (flags & ENQUEUE_DELAYED)
    {
        requeue_delayed_entity(se);
        return;
    }

    if (task_new && se->sched_delayed)
        h_nr_runnable = 0;

    for_each_sched_entity(se)
    {
        if (se->on_rq)
        {
            if (se->sched_delayed)
                requeue_delayed_entity(se);

            break;
        }

        cfs_rq = cfs_rq_of(se);

        enqueue_entity(cfs_rq, se, flags);

        cfs_rq->h_nr_runnable += h_nr_runnable;
        cfs_rq->h_nr_queued++;
    }

    for_each_sched_entity(se)
    {
    }

    /* At this point se is NULL and we are at root level*/
    add_nr_running(rq, 1);

    assert_list_leaf_cfs_rq(rq);
    hrtick_update(rq);
}
